<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input type="text" id="num1" />
    <select name="" id="sel">
      <option value="+">+</option>
      <option value="-">-</option>
      <option value="*">*</option>
      <option value="/">/</option>
    </select>
    <input type="text" id="num2" />
    <button id="but">计算</button>
    结果：<input type="text" id="end" />
    <script>
      var num1Element = document.getElementById("num1");
      var selectElement = document.getElementById("sel");
      var num2Element = document.getElementById("num2");
      var buttonElement = document.getElementById("but");
      var inputElement = document.getElementById("end");
      but.onclick = function () {
        var num1 = parseInt(num1Element.value);
        var num2 = parseInt(num2Element.value);
        var sel = selectElement.value;

        if (sel == "+") {
          var end = num1 + num2;
        } else if (sel == "-") {
          var end = num1 - num2;
        } else if (sel == "*") {
          var end = num1 * num2;
        } else if (sel == "/") {
          var end = num1 / num2;
        }
        console.log(end);
        inputElement.value = end;
      };
    </script>
  </body>
</html>
